package com.group525.cloudef.service.user.impl;

import com.group525.cloudef.Dao.user.UHazardDao;
import com.group525.cloudef.Dao.user.UStatisticDao;
import com.group525.cloudef.entity.user.UHazard;
import com.group525.cloudef.mapper.user.UHazardMapper;
import com.group525.cloudef.service.user.UHazardService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author group525
 * @since 2023-05-17
 */
@Service
public class UHazardServiceImpl extends ServiceImpl<UHazardMapper, UHazard> implements UHazardService {
    @Resource
    UHazardMapper UHazardMapper;

    @Override
    public List<UHazardDao> getHazard(){
        List<UHazard> hazard = UHazardMapper.getHazard();
        List<UHazardDao> hazardDaoList = new ArrayList<>();
        hazard.forEach(UHazard -> {
            UHazardDao uHazardDao = new UHazardDao();
            BeanUtils.copyProperties(UHazard,uHazardDao);

            Long userId = UHazard.getUserId();
            Long docId = UHazard.getDoctorId();
            String userName = UHazardMapper.getUserName(userId);
            String gender = UHazardMapper.getUserGender(userId);
            String age = UHazardMapper.getUserAge(userId);
            String docName = UHazardMapper.getDocName(docId);

            uHazardDao.setUsername(userName);
            uHazardDao.setGender(gender);
            uHazardDao.setAge(age);
            uHazardDao.setDocName(docName);
            hazardDaoList.add(uHazardDao);
        });
        return hazardDaoList;
    }
    @Override
    public UStatisticDao getCount(){
        UStatisticDao count = new UStatisticDao();
        count.setUserCount(UHazardMapper.getUserCount());
        count.setHazardCount(UHazardMapper.getHazardCount());
        return count;
    }

    @Override
    public UStatisticDao infectious(){
        UStatisticDao infectious = new UStatisticDao();
        infectious.setUserCount(UHazardMapper.getUserCount());
        infectious.setInfectious(UHazardMapper.getInfectCount());
        infectious.setFeiYan(UHazardMapper.getFeiYan());
        infectious.setJiHui(UHazardMapper.getJiHui());
        infectious.setBaiRiKe(UHazardMapper.getBaiRiKe());
        infectious.setLiuNao(UHazardMapper.getLiuNao());
        infectious.setFeiJieHe(UHazardMapper.getFeiJieHe());
        return infectious;
    }
}
